package com.tao.controller;

import com.tao.entity.Weibo;
import com.tao.mapper.WeiboMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.Date;
import java.util.List;


@RestController
public class WeiboController {
    @Autowired
    private WeiboMapper mapper;
    @RequestMapping("/insert")
    public void insert(@RequestBody Weibo weibo) {
        weibo.setCreateTime(new Date());
        System.out.println("weibo = " + weibo);
        mapper.insert(weibo);
    }
    @RequestMapping("/select")
    public List<Weibo> select(){
        System.out.println(mapper.select());
        return mapper.select();
    }
    @RequestMapping("/delete")
    public void delete(int id){
        String url = mapper.selectUrlById(id);
        new File("d:/files"+url).delete();
//        mapper.delete(id);
    }
    @RequestMapping("/selectById")
    public Weibo selectById(int id){
        return mapper.selectById(id);
    }
    @RequestMapping("/update")
    public void update(Weibo weibo){
        weibo.setCreateTime(new Date());
        System.out.println("weibo = " + weibo);
//        mapper.update(weibo);
    }
}
